#!/usr/bin/env python
# -*- coding: utf-8 -*-
########################################################################
# 
# Copyright (c) 2017 isworld.net, Inc. All Rights Reserved
# 
########################################################################
 
"""
File: downapi.py
Author: liuxufeng
Date: 2017/09/09 03:05:23
"""

import requests
import json
import urllib

server = "http://localhost:9001"


def download(url):
    _url = urllib.quote(url)
    url = "%s/?url=%s" % (server, _url)
    resp = requests.get(url)  # timeout = infinite
    cont = resp.content
    cont = json.loads(cont)
    code, data = cont['code'], cont['data']
    if code != 0:
        raise Exception("download error: code=[%s], data=[%s]" % (code, data))
    return data
    

def test():
    url = "https://public.lightpic.info/image/E49E_59AD58D70.jpg"
    print download(url)


if __name__ == "__main__": 
    test()


